/* montecarlo */

cap prog drop front
prog def front, rclass
    version 15.0
    use return, clear
    local w1 = runiform()
    local w2 = runiform()
    local w3 = runiform()
    mat weight = (`w1' \ `w2' \ `w3' )
    mat list weight
    mat weight = weight / (`w1'+`w2'+`w3')
    mat list weight
    ret scalar w1 = weight[1, 1]
    ret scalar w2 = weight[2, 1]
    ret scalar w3 = weight[3, 1]
    local j = 1
    foreach i of varlist _all{
        if "`i'" != "date"{
            qui sum `i'
            local r`j' = r(mean)
            local j = `j' + 1
        }
    }
    mat rets = (`r1', `r2', `r3')
    mat a =  rets * weight
    mat list a
    ret scalar ret = a[1, 1]
    corr 科大讯飞 贵州茅台 药明康德, cov
    ret list
    mat cov = r(C)
    mat b =  weight' * cov * weight
    mat list b
    ret scalar var = b[1, 1]
    ret scalar std = sqrt(b[1, 1])
end
